{extends file="index.tpl"}
{block name=head_title}Export{/block}
{block name=head_script}
    <script>
        $(document).ready(function () {
            var now = new Date();
            var day = ("0" + now.getDate()).slice(-2);
            var month = ("0" + (now.getMonth() + 1)).slice(-2);
            var today = now.getFullYear() + "-" + (month) + "-" + (day);
            $('#dateExport').val(today);
        });
    </script>
{/block}
{block name=head_style}{/block}
{block name=body}
    <!-- Table Add/Edit -->
    {if isset($action)}
        {if $action=="report"}
            <form id="frmReport" action="/export/report" method="post">
                <table cellspacing="0" cellpadding="3" align="center" border="1" class="table">
                    <thead>
                        <tr class="table_thead_tr">
                            <th colspan="2">
                                {"Report"|upper}
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr style="color:#000066;">
                            <td>Chọn ngày</td>
                            <td>
                                <input id="dateExport" name="dateExport" type="date" style="width: 200px">
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" style="text-align: center">  
                                <input type="submit" id="submit" name="submit" value="Export" />
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
        {/if}

        {if $action=="mail"}
            <form id="frmMail" action="/export/mail" method="post">
                <table cellspacing="0" cellpadding="3" align="center" border="1" class="table">
                    <thead>
                        <tr class="table_thead_tr">
                            <th colspan="2" style="padding:10px">
                                {"Danh sách email"|upper}
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        {if isset($email)}
                            {foreach from=$email item=i  }
                                <tr style="color:#000066;">
                                    <td style="padding: 10px">
                                        <span>{$i.Email}</span>
                                    </td>
                                    <td style="text-align: center; padding:10px">
                                        <a href="/export/mail/{$i.MaEmail}/delete" onclick="return confirm('Are you sure delete the email {$i.Email}?');"><img src="/images/delete.gif" /></a>
                                    </td>
                                </tr>
                            {/foreach}
                        {/if}
                        <tr style="color:#000066;">
                            <td style="padding:5px">
                                <input type="text" id="email" name="email" style="width: 200px; padding:5px"/>
                            </td>
                            <td style="padding:10px"> 
                                <input type="submit" id="submit" name="submit" value="Add" onclick="
                                        if (!IsEmail($('#email').val())) {
                                            alert('Email không hợp lệ');
                                            return false;
                                        }
                                       "/>
                            </td>
                        </tr>
                    </tbody>
                </table>
                <br />
                <table align="center" border="0">
                    <tr>
                        <td>
                            <input type="submit" id="submit" name="submit" value="Send Mail" style="font-size:18pt"/>
                        </td>
                    </tr>
                </table>
            </form>
            {if isset($error)}
                {if $error!="0"}
                    <pre>
                    <p style="font-size: 20pt; text-align: center; color: red">Mailer error: {$error}</p>
                    </pre>
                {else}
                    <p style="font-size:20pt; text-align: center;">Gửi email thành công!</p>
                {/if}
            {/if}
        {/if}
    {/if}
    {if isset($success)}
        <script>
            {if $success==1}
            alert("Thêm email thành công!");
            top.location.href = '/export/mail';
            {/if}
            {if $success==0}alert("Lỗi server, bạn hãy thử lại!");{/if}
            {if $success==-1}alert("Email này đã có rồi!");{/if}
        </script>
    {/if}
{/block}